﻿@{
    ViewBag.Title = "Home Page";
}
@section featured {
    <section class="featured">
        <div class="content-wrapper">
            <hgroup class="title">
                <h1>@ViewBag.Title.</h1>
                <h2>@ViewBag.Message</h2>
            </hgroup>
            <p>
                To learn more about ASP.NET MVC visit
                <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
                The page features <mark>videos, tutorials, and samples</mark> to help you get the most from ASP.NET MVC.
                If you have any questions about ASP.NET MVC visit
                <a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET MVC Forum">our forums</a>.
            </p>
        </div>
    </section>
}
<h3>We suggest the following:</h3>
<ol class="round">
    <li class="one">
        <h5>Getting Started</h5>
        ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
        enables a clean separation of concerns and that gives you full control over markup
        for enjoyable, agile development. ASP.NET MVC includes many features that enable
        fast, TDD-friendly development for creating sophisticated applications that use
        the latest web standards.
        <a href="http://go.microsoft.com/fwlink/?LinkId=245151">Learn more…</a>
    </li>

    <li class="two">
        <h5>Add NuGet packages and jump-start your coding</h5>
        NuGet makes it easy to install and update free libraries and tools.
        <a href="http://go.microsoft.com/fwlink/?LinkId=245153">Learn more…</a>
    </li>

    <li class="three">
        <h5>Find Web Hosting</h5>
        You can easily find a web hosting company that offers the right mix of features
        and price for your applications.
        <a href="http://go.microsoft.com/fwlink/?LinkId=245157">Learn more…</a>
    </li>
</ol>
<div id="UsersFromService"></div>

<script src="~/Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript">
    // Urls to access the WCF Rest service methods
    var GetUsersURI = "http://localhost:1216/api/users";
    //GetUsersURI = "http://localhost:1216/api/values";
    var nextStudentID = 1;
    var jDepartment = null;
    var jPendingStudent = null;

    // Utility function - Create HTML table on Json data
    function makeTable(jObject) {
        var jArrayObject = jObject
        if (jObject.constructor != Array) {
            jArrayObject = new Array();
            jArrayObject[0] = jObject;
        }

        var table = document.createElement("table");
        table.setAttribute('cellpadding', '4px');
        table.setAttribute('rules', 'all');
        var tboby = document.createElement("tbody");

        var trh = document.createElement('tr');
        for (var key in jArrayObject[0]) {
            var th = document.createElement('th');
            th.appendChild(document.createTextNode(key));
            trh.appendChild(th);
        }
        tboby.appendChild(trh);

        $.each(jArrayObject, function (i, v) {
            var tr = document.createElement('tr');
            for (var key in v) {
                var td = document.createElement('td');
                td.appendChild(document.createTextNode(v[key]));
                tr.appendChild(td);
            }
            tboby.appendChild(tr);
        });

        table.appendChild(tboby)

        return table;
    }

    $(document).ready(function () {
        $.ajax({
            cache: false,
            type: "GET",
            async: false,
            dataType: "json",
            url: GetUsersURI,
            success: function (department) {
                var table=makeTable(department);
                var span = document.createElement("span");
                span.appendChild(table);
                var div = document.createElement("div");
                div.appendChild(span);

                //var span = document.createElement("span");
                //span.appendChild(document.createTextNode("List of Users:"));
                //div.appendChild(span);
                //div.appendChild(document.createElement("br"));

                //for (var i = 0; i < department.length ; i++) {
                //    var item = department[i];

                //    var span = document.createElement("span");
                //    span.setAttribute('id', 'UserHeader');
                //    span.appendChild(document.createTextNode(item.UserId));
                //    span.appendChild(document.createTextNode(" - "));
                //    span.appendChild(document.createTextNode(item.UserName));
                //    div.appendChild(span);

                //    span = document.createElement("span");
                //    div.appendChild(document.createElement("br"));
                //    div.appendChild(span);
                //}

                $("#UsersFromService").html("").append(div);
                $("#UsersFromService").show(10);
            },
            error: function (xhr) {
                alert(xhr.responseText + ' ' + xhr.status);
            }
        });
    });
</script>
